﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Buy2Site.Classes;
using System.Globalization;

namespace Buy2Site.UserControls
{
    public partial class RegisterUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                using (Buy2SiteDBEntities entSite = new Buy2SiteDBEntities())
                {                    
                    
                    User user = new User()
                    {
                        UserName=txtUserName.Text,
                        Password=txtPassword.Text,
                        FirstName=txtFirstName.Text,
                        LastName=txtLastName.Text,
                        Email=txtEmail.Text,
                        // TODO - fix hour:min:sec added to date in database
                        BirthDate=DateTime.ParseExact(
                            txtBirthDate.Text,
                            "M/d/yyyy",
                            CultureInfo.InvariantCulture)
                    };
                    entSite.AddToUser(user);
                    entSite.SaveChanges();
                }
            }
        }

        protected void selectDate(object sender, EventArgs e)
        {
            txtBirthDate.Text = calander.SelectedDate.ToLocalTime().ToShortDateString();
        }
    }
}